Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix static-size FFI type aliases #463

Merged
merged 2 commits into from
Oct 27, 2024
Merged

Fix static-size FFI type aliases #463

merged 2 commits into from
Oct 27, 2024

Conversation

jakelishman
Copy link
Contributor

Several type aliases with statically sized names (e.g. npy_uint64) were being aliased to platform-dependent types like ::std::os::raw::c_long. Most of these were barely used, so it seems like they didn't cause problems before, but now with npy_uint64 being used in certain structs, which are the target of pointer punning, the mismatch in sizes became visible. For example, npy_uint64 was previously typedef'd to c_ulong, which is 64 bits on 64-bit platforms and on all Unix-likes, but 32 bits on Windows 32-bit. This caused inaccurate reads through pointers to structs containing them, eventually resulting in attempts to dereference null pointers.

That appears to be the only problem with win32 support, so the second commit re-adds it to the CI matrix and removes the enforced compiler error.

Fix #448

Several type aliases with statically sized names (e.g. `npy_uint64`)
were being aliased to platform-dependent types like
`::std::os::raw::c_long`.  Most of these were barely used, so it seems
like they didn't cause problems before, but now with `npy_uint64` being
used in certain structs, which are the target of pointer punning, the
mismatch in sizes became visible.  For example, `npy_uint64` was
previously typedef'd to `c_ulong`, which is 64 bits on 64-bit platforms
and on all Unix-likes, but 32 bits on Windows 32-bit.  This caused
inaccurate reads through pointers to structs containing them, eventually
resulting in attempts to derefence null pointers.
The parent commit fixes the problems with 32-bit Windows, this one
simply re-enables the build and re-activates the CI runs of it.
@maffoo
Copy link
Contributor

maffoo commented Oct 22, 2024

Thanks for digging into this!

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks very promising! Have triggered CI...

@davidhewitt davidhewitt merged commit 6cd2a84 into PyO3:main Oct 27, 2024
64 checks passed
@jakelishman jakelishman deleted the win32 branch October 27, 2024 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Numpy2 support fails when running with 32-bit windows
3 participants